import { Injectable } from '@angular/core';
import { LoadingController } from '@ionic/angular';

@Injectable({
    providedIn: 'root',
})
export class LoadingService {

    constructor(private loadCtrl: LoadingController) {

    }

    async load(message: string, time?: number, callback?) {
        let load;
        load = await this.loadCtrl.create({
            message: message,
            cssClass: 'custom-loading',
            spinner: 'bubbles'
        });
        load.onDidDismiss().then(() => {
            if (callback) {
                callback();
            }
        });
        load.present();
        return load;
    }
}
